You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
40 lines
1.3 KiB
import { updateTimelineEvent } from "#server/service/timeline";
|
|
import { visibilitySchema } from "#server/constants/visibility";
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
const user = await event.context.auth.requireUser();
|
|
const id = Number(event.context.params?.id);
|
|
if (!Number.isInteger(id)) {
|
|
throw createError({ statusCode: 400, statusMessage: "无效 id" });
|
|
}
|
|
const body = await readBody<{
|
|
occurredOn?: string;
|
|
title?: string;
|
|
bodyMarkdown?: string | null;
|
|
linkUrl?: string | null;
|
|
visibility?: string;
|
|
}>(event);
|
|
|
|
const occurredOn =
|
|
body.occurredOn !== undefined
|
|
? (() => {
|
|
const d = new Date(body.occurredOn);
|
|
if (Number.isNaN(d.getTime())) {
|
|
throw createError({ statusCode: 400, statusMessage: "occurredOn 无效" });
|
|
}
|
|
return d;
|
|
})()
|
|
: undefined;
|
|
|
|
const ev = await updateTimelineEvent(user.id, id, {
|
|
occurredOn,
|
|
title: body.title,
|
|
bodyMarkdown: body.bodyMarkdown,
|
|
linkUrl: body.linkUrl,
|
|
visibility: body.visibility !== undefined ? visibilitySchema.parse(body.visibility) : undefined,
|
|
});
|
|
if (!ev) {
|
|
throw createError({ statusCode: 404, statusMessage: "未找到" });
|
|
}
|
|
return R.success({ event: ev });
|
|
});
|
|
|